<?php
	class ProductDatabase{
		public function insert($mycategory, $myprice,$mydescription){
		?>
		
		<html xmlns="http://www.w3.org/1999/xhtml">
		<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" type="text/css" href="style.css" />
		<title>Wellcome to Charity Organization!</title>
		</head>

		<body>
		<div id="container">
		<div id="header">
			<h1>Charity<span class="off">Organization</span></h1>
        </div>   
        <div id="menu">
			<ul>
				<a href="Insert.php">Back</a>
            </ul>
        </div>
    
		<div id="content">
        <div id="content_top"></div>
		<div id="content_main">
		<?php
			$link =mysql_connect('localhost','root','');
			if (!$link) {
				die('Not connected : ' . mysql_error());
			}
			$db_selected = mysql_select_db('seproject', $link);
			if (!$db_selected) {
				die ('Cannot useSeproject : ' . mysql_error());
			}
			$Category= $mycategory;  $Price=$myprice; $Description=$mydescription;
		
			$query=mysql_query("SELECT Product_ID FROM `product`");
			$num=mysql_num_rows($query);
			for($i=0;$i<$num-1;$i++)
			{
				$a=mysql_fetch_row($query);
			}
			$last=mysql_fetch_row($query);
			$Product_ID='I'.($last[0][1]+1);
			
			$query1=mysql_query("INSERT INTO `seproject`.`product` (`Product_ID`, `Category`, `Price`,`Description`) VALUES ('$Product_ID', '$Category', '$Price', '$Description')");
			if($query1)
			{
				echo "Item has been inserted!";
				?>
				<a href="ManageStore.php">Back</a>
				<?php
			}
			else
			{
				echo "Insert item has been failed!";
				?>
				<a href="ManageStore.php">Back</a>
				<?php
			}	
			?>
        </div>
        <div id="content_bottom"></div>
		</div>
		</div>
		</body>
		</html>
		<?php
		}
		
		
		
		public function searchByPid($myId){
		?>
		<html xmlns="http://www.w3.org/1999/xhtml">
		<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" type="text/css" href="style.css" />
		<title>Wellcome to Charity Organization!</title>
		</head>
		
		<body>
		<div id="container">
				<div id="header">
					<h1>Charity<span class="off">Organization</span></h1>
				</div>   
				<div id="menu">
					<ul>
						<a href="Search.php">Back</a>
					</ul>
				</div>
			
				<?php
				$link =mysql_connect('localhost','root','');
				if (!$link) {
					die('Not connected : ' . mysql_error());
				}
				$db_selected = mysql_select_db('seproject', $link);
				if (!$db_selected) {
					die ('Cannot useSeproject : ' . mysql_error());
				}
				$Product_ID=$myId;
				$query = mysql_query("SELECT * FROM `seproject`.`product` where `Product_ID`='$Product_ID'");
				$num=mysql_num_rows($query);
				if($num>0)
				{
					?>
					<div id="content">
					<div id="content_main">
					<table cellspacing="10" border="0"   align="left" bgcolor="#FFFFFF"  bordercolor="#180000" frame="box">  
					<tr>
					<th>Product_ID</th>
					<th>Category</th>
					<th>Price</th>
					<th>Description</th>
					</tr>
					<?php
					for($i=0;$i<mysql_num_rows($query);$i++)
					{
						$a=mysql_fetch_row($query);
						?>
						<tr>
						<td><?php echo $a[0]; ?></td>
						<td><?php echo $a[1]; ?></td>
						<td><?php echo $a[2]; ?></td>
						<td><?php echo $a[3]; ?></td>
						</tr>
						<?php
					}
					?>
					</table>
					</div>
					<?php
				}
				else
				{
					?>
					<div id="content">
					<div id="content_top"></div>
					<div id="content_main">
					<?php
					echo "Item not found";
					?>
					<a href="Search.php">Back</a>
					</div>
					<div id="content_bottom"></div>
					<?php
				}
				?>
				</div>
				
			</div>
		</div>
		</body>
		</html>
		<?php
		}
		public function searchByCategory($myCategory){
		?>
		
		<html xmlns="http://www.w3.org/1999/xhtml">
		<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" type="text/css" href="style.css" />
		<title>Wellcome to Charity Organization!</title>
		</head>
		
		<body>
		<div id="container">
				<div id="header">
					<h1>Charity<span class="off">Organization</span></h1>
				</div>   
				<div id="menu">
					<ul>
						<a href="Search.php">Back</a>
					</ul>
				</div>
			
				<?php
				$link =mysql_connect('localhost','root','');
				if (!$link) {
					die('Not connected : ' . mysql_error());
				}
				$db_selected = mysql_select_db('seproject', $link);
				if (!$db_selected) {
					die ('Cannot useSeproject : ' . mysql_error());
				}
				$Category=$myCategory;
				$query = mysql_query("SELECT * FROM `seproject`.`product` where `Category`='$Category'");
				$num=mysql_num_rows($query);
				if($num>0)
				{
					?>
					<div id="content">
					<div id="content_main">
					<table cellspacing="10" border="0"   align="left" bgcolor="#FFFFFF"  bordercolor="#180000" frame="box">  
					<tr>
					<th>Product_ID</th>
					<th>Category</th>
					<th>Price</th>
					<th>Description</th>
					</tr>
					<?php
					for($i=0;$i<mysql_num_rows($query);$i++)
					{
						$a=mysql_fetch_row($query);
						?>
						<tr>
						<td><?php echo $a[0]; ?></td>
						<td><?php echo $a[1]; ?></td>
						<td><?php echo $a[2]; ?></td>
						<td><?php echo $a[3]; ?></td>
						</tr>
						<?php
					}
					?>
					</table>
					</div>
					<?php
				}
				else
				{
					?>
					<div id="content">
					<div id="content_top"></div>
					<div id="content_main">
					<?php
					echo "Item not found";
					?>
					<a href="Search.php">Back</a>
					</div>
					<div id="content_bottom"></div>
					<?php
				}
				?>
				</div>
				
			</div>
		</div>
		</body>
		</html>
		<?php
		}
		public function editProduct($myProductId, $myCategory, $myPrice, $myDescription){
		?>
		<html xmlns="http://www.w3.org/1999/xhtml">
		<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" type="text/css" href="style.css" />
		<title>Wellcome to Charity Organization!</title>
		</head>
		
		<body>
		<div id="container">
				<div id="header">
					<h1>Charity<span class="off">Organization</span></h1>
				</div>   
				<div id="menu">
				</div>
			
				<div id="content">
				<div id="content_top"></div>
				<div id="content_main">
				<?php
				$link =mysql_connect('localhost','root','');
				if (!$link) {
					die('Not connected : ' . mysql_error());
				}
				$db_selected = mysql_select_db('seproject', $link);
				if (!$db_selected) {
					die ('Cannot useSeproject : ' . mysql_error());
				}
				$Product_ID=$myProductId;
				$Category=$myCategory;$Price=$myPrice;$Description=$myDescription;
				$sql = mysql_query("update `seproject`.`product` set `Category`='$Category' ,`Price`='$Price',`Description`='$Description' where `Product_ID`='$Product_ID'");
				if($sql)
				{
					echo "Product information has been changed!";
					?>
					<a href="ManageStore.php">Back</a>
					<?php
				}
				else
				{
					echo "Change information has been failed!";
					?>
					<a href="ManageStore.php">Back</a>
					<?php
				}
				?>
				</div>
				<div id="content_bottom"></div>
			</div>
		</div>
		</body>
		</html>
		<?php
		
		}
		public function deleteProduct($myProductId){
		?>
		
		<html xmlns="http://www.w3.org/1999/xhtml">
		<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" type="text/css" href="style.css" />
		<title>Wellcome to Charity Organization!</title>
		</head>
		
		<body>
		<div id="container">
				<div id="header">
					<h1>Charity<span class="off">Organization</span></h1>
				</div>   
				
				<div id="menu">
					<ul>
						<a href="ManageStore.php">Back</a>
					</ul>
				</div>
			
				<div id="content">
				<div id="content_top"></div>
				<div id="content_main">
				<?php
					$link =mysql_connect('localhost','root','');
					if (!$link) {
						die('Not connected : ' . mysql_error());
					}
					$db_selected = mysql_select_db('seproject', $link);
					if (!$db_selected) {
						die ('Cannot useSeproject : ' . mysql_error());
					}
					$Product_ID=$myProductId;
					$query= mysql_query("delete FROM `seproject`.`product` WHERE `Product_ID`='$Product_ID'");
					if($query)
					{
						echo "Selected Item has been deleted!";
						?>
						<a href="ManageStore.php">Back</a>
						<?php
					}
					else
					{
						echo "Delete item has been failed!";
						?>
						<a href="ManageStore.php">Back</a>
						<?php
					}
				?>	
				</div>
				<div id="content_bottom"></div>
			</div>
		</div>
		</body>
		</html>
		<?php
		}
		
	}
?>